/*
 * 人人信用管理有限公司版权所有.
 * 
 * @Description:
 * 
 * @author: liyuliang
 * 
 * @date: 20 Apr 2017 10:44:16 am
 * 
 * 注意：本内容仅限于人人信用管理有限公司内部传阅，禁止外泄以及用于其他的商业目的.
 */

package com.rrx360.common.util;

public class StringUtil {

  public static boolean equal(String s1, String s2) {
    if (s1 == null) {
      if (s2 == null || s2.length() == 0) {
        return true;
      }
      return false;
    } else {
      if (s1.length() == 0 && s2 == null) {
        return true;
      }
      return s1.equals(s2);
    }


  }

  public static String get(Object o) {
    if (o == null) {
      return null;
    }
    if (o instanceof String) {
      return (String) o;
    }
    return o.toString();
  }

  public static int compare(String s1, String s2) {
    if (s1 == null) {
      return -1;
    }
    if (s2 == null) {
      return 1;
    }
    return s1.compareTo(s2);
  }

  public static Character getFirstLetter(String s) {
    if (s == null || s.length() == 0) {
      return null;
    }
    return s.charAt(0);

  }

  public static String subString(String s, int length) {
    if (s == null || s.length() <= length) {
      return s;
    }
    return s.substring(0, length);
  }
}
